<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class Printer extends Model
{
    private $fields = array('realname','gender','birthday','idcard','address','endtime');
    protected $table = 'tp_print_log';

    function mainData($size=10,$where=''){
        $map[] = ['p.id','>','0'];
        $count = Db::name('print_log')->alias('p')->where($map)->count();// 查询满足要求的总记录数

        $list = Db::name('print_log')
            ->alias('p')
            ->join("tp_admin a",'p.admin_id = a.admin_id', 'left')
           ->field('p.*,a.user_name')
            ->where($map)
            ->order('p.id desc')
            ->paginate($size,$count,['query'=>request()->param()])
            ->each(function($item,$key){
                return $item;
            });
        $page = $list->render();

        $data['count'] = $count;
        $data['list'] = $list;
        $data['page'] = $page;
        return $data;
    }

    //处理参数
    function disposeData($data,$act=''){

        $newData = array_elements($this->fields, $data);

        return $newData;
    }
}